package com.neusoft.dibuy.th;

import java.util.Scanner;

public class MyInterrupt {
    public static void main(String[] args) {
        MyThread3 mt = new MyThread3();
        Thread thread = new Thread(mt);
        thread.start();
        Scanner sc = new Scanner(System.in);
        do {
            System.out.println("MyInterrupt.main :_______________");
            String line = sc.nextLine();
            if ("1".equals(line))
            {
                mt.stop();
                break;
            }
        }while (true);
        System.out.println("----------------");
    }
}

class MyThread3 implements Runnable {
    private boolean flag = true;
    public void stop(){
        this.flag = false;
    }
    public void run()
    {
        while (flag)
        {
            System.out.println("线程正在运行");
            try
            {
                Thread.sleep(1000);
            } catch (InterruptedException e)
            {
                System.out.println("线程被中断");
                break;
            }
        }
    }
}